<?php
$hostname = "localhost";
$username = "root";
$password = "root";
$dbname   = "yasi";
$conn = mysql_connect($hostname, $username, $password) or die ("Error: could not connect to database");
mysql_select_db($dbname);

$userid = addslashes($_POST['userid']);
$userinfo = array();
foreach($_POST as $key=>$value){
	if($key != 'userid'){
		$userinfo[$key] = $value;
	}
}

$result = mysql_query("select * from tb_whv_user where user_id='".$userid."'");
if($row = mysql_fetch_array($result)){
	mysql_query("update tb_whv_user set user_info = '".json_encode($userinfo)."' where user_id = '".$userid."'");
}else{
	mysql_query("INSERT INTO tb_whv_user (user_id, user_info) VALUES ('".$userid."', '".json_encode($userinfo)."')");
}
mysql_close($conn);
echo('success');
?>
